package com.efast.dmom.mes.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.bean.Uom;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.UomService;

@Controller
@RequestMapping("/uom")
public class UomController {
	
	@Autowired
	private UomService uomService;
	
	@RequestMapping(value = "/verifyUnit")
	public @ResponseBody ResultBean verifyUnit(@RequestBody Uom uom) {
		return uomService.verifyUnit(uom);
	}
	
	@RequestMapping(value = "/deleteUnit")
	public @ResponseBody ResultBean deleteUnit(@RequestBody Uom uom) {
		return uomService.deleteUnit(uom);
	}
	
	//单位名称唯一性校验
	@RequestMapping(value = "/uniqueVerifyUom")
	public @ResponseBody ResultBean uniqueVerifyUom(@RequestBody Uom uom) {
		return uomService.uniqueVerifyUom(uom);
	}
	
	@RequestMapping(value = "/operateByUom")
	public @ResponseBody ResultBean operateByUom(@RequestBody Uom uom) {
		ResultBean resultBean = new ResultBean(true, ' ');
		// Judge to add
		if (uom.getModificationFlag() == IModificationFlags.NEW) {
			return uomService.save(uom);
	    // Judge to update
		} else if (uom.getModificationFlag() == IModificationFlags.MODIFIED) {
			return uomService.update(uom);
		} 
		return resultBean;
	}

}
